<?php
declare(strict_types = 1);

namespace leruge\command;

use think\console\Command;

class Gateway extends Command
{
    public function configure()
    {
        $this->setName('gateway')
            ->setDescription('win下gateway启动');
    }

    public function handle()
    {
        $this->output->info('gateway启动');
        $registerAddress = config('chat.register_address') ?: '127.0.0.1:1201';
        $gatewayAddress = config('chat.gateway_address') ?: 'websocket://0.0.0.0:8201';
        $gateway = new \GatewayWorker\Gateway($gatewayAddress);
        $gateway->name = config('chat.gateway_name') ?: 'gateway';
        $gateway->count = config('chat.gateway_count') ?: 1;
        $gateway->lanIp = config('chat.gateway_lan_ip') ?: '127.0.0.1';
        $gateway->startPort = config('chat.gateway_start_port') ?: 4001;
        $gateway->registerAddress = $registerAddress;
        $gateway->pingInterval = config('gateway.gateway_ping_interval') ?: 55;
        $gateway->pingNotResponseLimit = 0;
        $gateway->pingData = '{"type":"ping"}';
        \Workerman\Worker::runAll();
    }
}